package com.tt.dp.command.invoke;

import com.tt.dp.command.Command;
import com.tt.dp.command.EmptyCommand;

public class RemoteControl {

    private Command[] ons;

    private Command[] offs;

    private Command undoCommand;

    public RemoteControl() {
        this.ons = new Command[7];
        this.offs = new Command[7];

        Command command = new EmptyCommand();
        for (int i = 0; i < 7; i++) {

            this.ons[i] = command;
            this.offs[i] = command;
        }

        this.undoCommand = command;
    }

    public void setCommand(int slot, Command onCommand, Command offCommand) {
        this.ons[slot] = onCommand;
        this.offs[slot] = offCommand;
    }

    private void setUndoCommand(Command command){
        this.undoCommand = command;
    }

    public void onButtonWasPushed(int slot){
        this.ons[slot].execute();
        setUndoCommand(this.ons[slot]);
    }

    public void offButtonWasPushed(int slot){
        this.offs[slot].execute();
        setUndoCommand(this.offs[slot]);
    }

    public void undoButtonWasPushed(){
        this.undoCommand.undo();
    }


}
